/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hci;

import backend.*;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.ActionMap;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.ApplicationContext;
import org.jdesktop.application.ResourceManager;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import hci.ListarCategorias;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

/**
 *
 * @author Capx
 */
public class Home extends SingleFrameApplication {

    private JFrame myFrame;
    private JPanel leftPanel;
    private JPanel homePanel;
    private JPanel rightPanel;

    @Action
    public void listarCategorias(ActionEvent e){
        ListarCategorias categorias;
        homePanel.setVisible(false);
        categorias = new ListarCategorias(leftPanel, homePanel);
        categorias.initialize();
/*        leftPanel.add(new JLabel("nuevo"));
        leftPanel.setVisible(true);
        leftPanel.revalidate();*/
//        labelVotos.setText("");
    }

    @Override protected void startup() {
//        Locale.setDefault(Locale.US);
        ApplicationContext ctx = Application.getInstance().getContext();
        /*lo que agregue yo*/
//        ResourceManager resource = ctx.getResourceManager();
//        ResourceMap map2 = resource.getResourceMap(Ejercicio1.class);
        /****************************************/
//        map2.getString("algo");
        ActionMap map = ctx.getActionMap(this);

        myFrame = getMainFrame();

        leftPanel = new JPanel();
        rightPanel = new JPanel();

        /*Armo la grilla para ubicar las componentes*/
        myFrame.getContentPane().setLayout(new GridBagLayout());

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.fill = GridBagConstraints.BOTH;
        myFrame.getContentPane().add (leftPanel, constraints);

        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.weighty = 1.0;
        constraints.weightx = 1.0;
        myFrame.getContentPane().add (rightPanel, constraints);
        constraints.weighty = 0.0;


        leftPanel.setBackground(Color.red);
        rightPanel.setBackground(Color.blue);

        myFrame.setTitle("framePpal");

//        myFrame.setLayout(new GridLayout(1, 2));

//        myFrame.setLayout(new BorderLayout());
        /*Paneles*/


        homePanel = new JPanel();
        homePanel.setLayout(new GridLayout(0,1));

//        rightPanel.add(new JButton("algo"));

        JButton categorias = new JButton("Listar Categorias");
        categorias.setAction(map.get("listarCategorias"));
        categorias.setText("Listar Categorias");

        homePanel.add(new JLabel("Menú principal"));
//        rightPanel.add(new JLabel("der"));

        homePanel.add(categorias);
        leftPanel.add(homePanel);

//        myFrame.add(leftPanel);
//        myFrame.add(rightPanel);
//        myFrame.add(leftPanel);
//        myFrame.add(rightPanel);

        myFrame.pack();

        show(myFrame);
    }

     public static void main(String[] args) {
/*        Languages in = new Languages();
        in.initialize();
        Categories ca = new Categories();
        ca.initialize();
        Subcategories sub = new Subcategories();
        sub.initialize();
        ProductsCat cat = new ProductsCat();
        cat.initialize();
        ProductsSubCat subCat = new ProductsSubCat();
        subCat.initialize();
        ProductsSearch search= new ProductsSearch();
        search.initialize();
        ProductByID id = new ProductByID();
        id.initialize();


        for(int i=0; i<in.getLanguages().length; i++)
                System.out.println(in.getLanguages()[i]);

        for(int i=0; i<ca.getCategories().length; i++)
                System.out.println(ca.getCategories()[i]);

        for(int i=0; i<sub.getSubcategories().length; i++)
                System.out.println(sub.getSubcategories()[i]);

        System.out.println("-------------CAT---------------------");
        for(int i=0; i<cat.getProducts().size(); i++){
                System.out.println("PRODUCTO "+i);
                System.out.println(cat.getProducts().get(i));
        }

        System.out.println("------------SUB-CAT------------------");
        for(int i=0; i<subCat.getProducts().size(); i++){
                System.out.println("PRODUCTO "+i);
                System.out.println(subCat.getProducts().get(i));
        }

        System.out.println("------------SEARCH------------------");
        for(int i=0; i<subCat.getProducts().size(); i++){
                System.out.println("PRODUCTO "+i);
                System.out.println(search.getProducts().get(i));
        }
        System.out.println("------------DETAILS------------------");
        System.out.println(id.getProduct());*/

        launch(Home.class, args);
    }
}
